const express = require('express')
const fs = require('fs')
const path = require('path')
const router = express.Router()

router.post('/', (req, res) => {
  const { fileName } = req.query

  const filePath = path.join(__dirname, 'uploads', fileName)

  console.log(filePath)
  if (!fs.existsSync(filePath)) {
    return res.errHandle('文件不存在')
  }

  const stats = fs.statSync(filePath)

  // console.log(stats)

  res.send({
    code: 200,
    message: 'success',
    data: {
      fileName,
      size: stats.size,
      type: path.extname(filePath).slice(1)
    }
  })
})

module.exports = router
